<template>
	<view class="login">
		<u-navbar :border-bottom="false" ></u-navbar>
		<view class="title acea-row row-column">
			<text>欢迎使用小鹭搜课</text>
			<text>未绑定的手机号将无法登录，请联系后台管理员</text>
		</view>
		<view class="container acea-row row-column">
			<text class="text">手机号码</text>
			<view class="input acea-row row-middle" :style="mobile?'border-bottom: 2rpx solid #1661FF;':'border-bottom: 2rpx solid #EBEDF0;'">
				<view class="left">+86</view>
				<view class="right">
					<u-input type="number" @input="mobileInput" class="right-input" :value="showMobile" placeholder="请输入您的手机号码" placeholder-style="font-size: 32rpx;color: #c0c4cc;line-height: 56rpx;font-weight: 400;"/>
				</view>
			</view>
			<!-- <u-field
				class="field"
				v-model="mobile"
				label-width="74"
				label="+86"
				:field-style="fieldStyle"
				placeholder="请填写手机号"
			></u-field>
			<u-field
				class="field"
				v-model="code"
				label-width="0"
				:field-style="fieldStyle"
				placeholder="请填写验证码"
			>
				<u-button size="mini" slot="right" type="default" plain :hair-line="false" hover-class="none" :custom-style="customStyle" @click="getCode">{{codeText}}</u-button>
				<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
			</u-field> -->
		</view>
		<button type="default" :class="checkMobile?'btn':'btn-disable'" @click="go2code">获取短信验证码</button>
		<!-- <view class="goLogin" @click="common.go('/pages/login/login')">微信用户一键登录</view> -->
		<login-footer />
	</view>
</template>

<script>
	import common from '../../../api/common.js'
	import request from '../../../api/request.js'
	const app = getApp()
	export default{
		data(){
			return{
				common,
				errorPhoneMessage:"手机号错误",
				mobile: '',
				showMobile:'',
				checkMobile: false,
				code: '',
				codeText: '',
				fieldStyle:{
					fontSize:"30rpx"
				},
				customStyle:{
					border:"none",
					color:"#1661FF",
					fontSize:"30rpx"
				},
			}
		},
		methods:{
			codeChange(text) {
				this.codeText = text;
			},
			go2code(){
				if(this.checkMobile){
					let data = {
						mobile:this.mobile
					}
					if(app.globalData.isWxwork){
						request.go((e)=>{
							this.common.go('/pages/pack/login/login-code?mobile='+this.mobile)
						},'/qywechat/sendverifycode',data,'POST')
					}else{
						request.go((e)=>{
							this.common.go('/pages/pack/login/login-code?mobile='+this.mobile)
						},'/Login/sendverifycode',data,'POST')
					}
				}
			},
			mobileChange(e){
				let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
				if(reg.test(e)){
					this.checkMobile = true
				}else{
					this.checkMobile = false
					uni.showToast({
						icon:"none",
						title:"手机号错误"
					})
				}
			},
			mobileInput(e){
				let text = JSON.parse(JSON.stringify(e)) 
				text = text.replace(/\s/g,"")
				// console.log(text,e)
				let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
				if(reg.test(text)){
					this.checkMobile = true
				}else{
					this.checkMobile = false
				}
				this.mobile = text
				this.setShowMobile(e)
			},
			setShowMobile(e){
				if(e.length === 4){
					e = e.substr(0,3) + " " + e.substr(3)
				}
				if(e.length === 9){
					e = e.substr(0,8) + " " + e.substr(8)
				}
				this.showMobile = e
			},
			getCode() {
				if(this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 1000);
				}else {
					this.$u.toast('倒计时结束后再发送');
				}
			}
		}
	}
</script>

<style scoped>
	.title{
		margin-top: 96rpx;
		margin-left: 64rpx;
	}
	.title text:nth-child(1){
		font-size: 56rpx;
		font-weight: 500;
		color: #1f2329;
		line-height: 80rpx;
	}
	.title text:nth-child(2){
		font-size: 26rpx;
		font-weight: 400;
		color: #8f959e;
		line-height: 36rpx;
		margin-top: 8rpx;
	}
	.container{
		margin: 96rpx auto 0;
		width: 622rpx;
	}
	.container .text{
		font-size: 28rpx;
		font-weight: 500;
		color: #646a73;
		line-height: 40rpx;
	}
	.container .input{
		width: 622rpx;
		margin-top: 16rpx;
		height: 96rpx;
		/* width: calc(100% - 128rpx); */
		/* margin: 0 auto; */
		border-bottom: 2rpx solid #1661FF;
		flex-wrap: nowrap;
	}
	.container .input .left{
		font-size: 40rpx;
		font-family: PingFang SC, PingFang SC-Semibold;
		font-weight: 600;
		color: #1f2329;
		line-height: 56rpx;
		padding-right: 24rpx;
		position: relative;
	}
	.container .input .left::after{
		content: " ";
		width: 2rpx;
		height: 32rpx;
		background-color: #EBEDF0;
		position: absolute;
		right: 0;
		top: 50%;
		transform: translateY(-50%);
	}
	.container .input .right{
		margin-left: 24rpx;
	}
	.container .input .right >>> .u-input__input{
		font-size: 40rpx;
		font-weight: 700;
		color: #1f2329;
		line-height: 56rpx;
		letter-spacing: 0rpx;
		font-family: none !important;
	}
	.container .field{
		margin-bottom: 30rpx;
		display: block;
	}
	.container .field:last-of-type{
		margin-bottom: 0rpx;
	}
	.container >>> .u-field{
		padding: 24rpx 0;
	}
	.btn{
		width: 654rpx;
		height: 88rpx;
		background: #1661ff;
		border-radius: 88rpx;
		color: #FFFFFF;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		line-height: 88rpx;
		margin-top: 98rpx;
	}
	.btn-disable{
		width: 654rpx;
		height: 88rpx;
		background: #1661ff;
		border-radius: 88rpx;
		color: #FFFFFF;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		line-height: 88rpx;
		margin-top: 98rpx;
		opacity: 0.3;
	}
	.goLogin{
		margin-top: 64rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		color: #909599;
		line-height: 40rpx;
		text-align: center;
	}
</style>
